Repository navigation
[Fix][CDC] Keep the live schema on restore when schema change propagation is disabled - #12321
Conversation
…tion is disabled Since apache#11503, IncrementalSourceReader restores the checkpointed runtime schema on every savepoint/checkpoint restore. For a job that does not propagate schema changes (schema-changes.enabled=false, the default) the change stream never emits DDL or RELATION events, so a column added while the job was stopped is dropped from every restored row and the sink keeps writing NULL for it. OpengaussCDCIT#testAddFieldWithRestore has been red on dev since that merge. Only restore the checkpoint schema when schema change propagation is enabled; otherwise keep the schema discovered from the live database, as before apache#11503. Debezium table history is still restored in both cases. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Posting this as a plain issue comment rather than a What Problem Does This PR Solve?
1. Code Change Review1.1 Core Logic AnalysisCore changes: Before: static <T> void restoreCheckpointState(
IncrementalSplit incrementalSplit,
DebeziumDeserializationSchema<T> debeziumDeserializationSchema) {
List<CatalogTable> checkpointTables = incrementalSplit.getCheckpointTables();
if (checkpointTables != null && !checkpointTables.isEmpty()) {
...
debeziumDeserializationSchema.restoreCheckpointProducedType(checkpointTables);
} else if (incrementalSplit.getCheckpointDataType() != null) {
... // legacy path, same unconditional restore
}
// history table changes restored unconditionally
}After: static <T> void restoreCheckpointState(
IncrementalSplit incrementalSplit,
DebeziumDeserializationSchema<T> debeziumDeserializationSchema,
boolean schemaChangeEnabled) {
List<CatalogTable> checkpointTables = incrementalSplit.getCheckpointTables();
if (!schemaChangeEnabled) {
if ((checkpointTables != null && !checkpointTables.isEmpty())
|| incrementalSplit.getCheckpointDataType() != null) {
log.info("... schema change propagation is disabled ... live discovered schema is kept ...");
}
} else if (checkpointTables != null && !checkpointTables.isEmpty()) {
...
debeziumDeserializationSchema.restoreCheckpointProducedType(checkpointTables);
} else if (incrementalSplit.getCheckpointDataType() != null) {
... // legacy path, unchanged when schemaChangeEnabled == true
}
// history table changes still restored unconditionally
}
static boolean isSchemaChangeEnabled(SourceConfig sourceConfig) {
if (sourceConfig instanceof JdbcSourceConfig) {
return ((JdbcSourceConfig) sourceConfig).getDbzConnectorConfig().isSchemaChangesHistoryEnabled();
}
return false;
}Call site ( Key findings:
In-depth correctness analysis:
1.2 Compatibility ImpactFully compatible. This is a bug-fix that restores the reader's original, pre-#11503 contract for the (default) 1.3 Performance / Side-Effect Analysis
1.4 Error Handling and LoggingThe new No blocking or non-blocking issues found in the production code. 2. Code Quality Assessment2.1 Coding StandardsBoth new/changed methods carry thorough Javadoc explaining the why, not just the what — 2.2 Test Coverage and Test StabilityCoverage is comprehensive for the branch this PR adds: the four pre-existing tests (checkpoint-tables restore, empty split, current-format restore, legacy-format restore) are all updated to pass Test-stability conclusion (Section 5.10.2): All tests (existing and new) are pure Mockito-based unit tests with no threads, no 2.3 Documentation UpdatesNo 3. Architectural Soundness3.1 Elegance of the SolutionPrecise fix. It conditions the restore decision on the actual capability (can the job widen a restored schema afterward?) rather than adding a special case for the specific regression test, and it applies uniformly to both the current and legacy checkpoint-schema formats and to every connector that goes through the shared reader, including correctly generalizing to non-JDBC (MongoDB) sources via the 3.2 MaintainabilityThe gate is centralized in one method ( 3.3 ExtensibilityIf a future non-JDBC connector does gain its own schema-change propagation mechanism, 3.4 Historical-Version CompatibilityFully compatible, as discussed in 1.2 — no checkpoint format or config surface changes; this restores prior, correct behavior for the default configuration rather than introducing a new one. Jobs upgrading into this fix need no migration action; they simply stop losing columns on restore. 4. Issue SummaryNo blocking or non-blocking issues found. 5. Merge RecommendationConclusion: Ready to merge
Overall assessment: I traced the full config chain from |
davidzollo
left a comment
There was a problem hiding this comment.
Maintainer Review
Root cause verified against dev CI logs. This is a real behavioural regression from #11503, not test flakiness: IncrementalSourceReader#restoreCheckpointState unconditionally restores the checkpointed runtime schema whenever checkpoint tables are present, discarding any column added to the source table while the job was stopped. That is correct for a job that propagates schema changes downstream (the stream itself will widen the schema again), but wrong for the default schema-changes.enabled = false, where nothing ever widens it again — the column stays dropped permanently.
Fix scope confirmed minimal and correctly gated. Checked the only production call site (initializedState) and confirmed no other caller of the 2-arg restoreCheckpointState exists outside this PR's own test file, so the added schemaChangeEnabled parameter is exhaustively threaded through. isSchemaChangeEnabled mirrors the exact flag (isSchemaChangesHistoryEnabled()) that already gates DDL emission in the MySQL connector and RELATION-message handling in the PostgreSQL connector, so it is not a new independent switch — it reuses an existing, already-audited contract. Debezium table history restore is correctly left unconditional in both branches, since it only drives decoding of the change stream and is never itself widened by SeaTunnel.
Backward compatibility verified. When schema-changes.enabled = true, behavior is byte-for-byte unchanged from #11503 (confirmed via diff: the else if branch is the original code, untouched). Only the false (default) path changes, and it changes back to the pre-#11503 contract — restoring what every existing job without schema-change propagation already relied on before the regression. No config, checkpoint format, or public API changed.
Tests have real failure capability. restoreCheckpointStateKeepsLiveSchemaWhenSchemaChangesAreDisabled and its legacy-checkpoint sibling both assert restoreCheckpointProducedType is never invoked when the flag is false — reverting the if (!schemaChangeEnabled) guard would make these fail immediately, and they exercise the exact branch this PR adds rather than mirroring the implementation. isSchemaChangeEnabledMirrorsDebeziumIncludeSchemaChanges pins the JDBC/non-JDBC resolution logic directly. The unchanged pre-existing restore tests now explicitly pass true, preserving their original #11503 coverage.
CI: Build, labeler, and Notify test workflow all green on the current head.
No blocking items. Approving.
🤖 Generated with Claude Code
Since apache#12321 the checkpoint schema is only restored when the job propagates schema changes, so the test now uses a JDBC source config with schema-changes enabled.
Summary
Since #11503 merged (2026-09-13 04:01Z),
dev's ownall-connectors-it-2job has been red on every completed run withOpengaussCDCIT#testAddFieldWithRestore(actual iterable was <null> at index [1][4]); the same failure shows up on unrelated PRs (#11077, #12216, ...). The last green dev run for that job is34581442965(2026-09-11). Earlier red runs on 09-12/09-13 were masked by the minio Docker Hub outage (IcebergSourceITfailed first and banned the rest of the reactor), which is why this surfaced only after #12287.This is a behavioural regression in CDC savepoint restore, not a flaky test: a column added to the source table while the job was stopped is silently dropped from every row written after the restore.
Root cause (log-confirmed on dev run
34821874806, jobRun / all-connectors-it-2 (8))The test takes a savepoint, runs
ALTER TABLE ... ADD COLUMN f_bigon source and sink, inserts a row, and restores the job. The reader log shows what #11503's restore path does now:Execution chain:
IncrementalSourceReader#initializedState->restoreCheckpointStatenow callsDebeziumDeserializationSchema#restoreCheckpointProducedType(checkpointTables)whenever the split carries checkpoint tables (before [Fix][CDC][Zeta] Restore runtime schema from checkpoint after failover #11503 this was gated on the deprecatedcheckpointDataType, which was never set, so the live-discovered schema was always kept).SeaTunnelRowDebeziumDeserializeSchema#restoreCheckpointProducedTypereplaces the schema discovered from the live database at startup (restore before, which already containsf_big) with the checkpoint schema (restore after, which predates the DDL) and queues aRestoreTableSchemaEvent.f_big, so the sink column staysNULLand the test'sassertIterableEquals(source, sink)fails at the new column of the inserted row.schema-changes.enabled = false, and that same flag is what gates DDL emission in the MySQL connector (include.schema.changes) and the RELATION listener in the PostgreSQL connector (PostgresSourceFetchTaskContext#configure,connectorConfig.isSchemaChangesHistoryEnabled()). With propagation disabled the narrowed schema is permanent until the job is restarted without state.#11503 targeted the opposite situation: a failover of a job that does propagate schema changes, where events between the checkpoint offset and a later DDL must be decoded with the checkpointed schema and the DDL in the stream widens it afterwards. That reasoning only holds when the stream is allowed to carry schema changes.
Fix
IncrementalSourceReader(connector-cdc-base only):restoreCheckpointStategains aschemaChangeEnabledargument. When it is false, the checkpoint schema (newcheckpointTablesformat and the legacycheckpointDataType) is not restored and the live-discovered schema stays authoritative, which is exactly the pre-[Fix][CDC][Zeta] Restore runtime schema from checkpoint after failover #11503 contract for these jobs; an INFO line records the decision. When it is true, [Fix][CDC][Zeta] Restore runtime schema from checkpoint after failover #11503's behaviour is unchanged.restoreCheckpointHistoryTableChanges) is restored in both cases: it only drives decoding of the change stream itself and SeaTunnel never widens it, so it stays correct for events between the checkpoint offset and a DDL.isSchemaChangeEnabled(SourceConfig)resolves the flag fromJdbcSourceConfig#getDbzConnectorConfig().isSchemaChangesHistoryEnabled(), the very switch every JDBC CDC connector derives fromschema-changes.enabled; non-JDBC sources (no schema change events at all) report false.Scope: one production file, one test file. No connector, option, checkpoint format, sink, or E2E change.
OpengaussCDCIT#testAddFieldWithRestoreis left exactly as it is; it is the E2E regression proof.Semantics
schema-changes.enabled = false(default), column added while stoppedschema-changes.enabled = true, failover / restoreTests
IncrementalSourceReaderTest:schemaChangeEnabled = trueand keep asserting [Fix][CDC][Zeta] Restore runtime schema from checkpoint after failover #11503's behaviour;restoreCheckpointStateKeepsLiveSchemaWhenSchemaChangesAreDisabled: checkpoint tables present, propagation disabled ->restoreCheckpointProducedTypenever called, history still restored;restoreCheckpointStateKeepsLiveSchemaForLegacyCheckpointWhenSchemaChangesAreDisabled: same rule for the legacycheckpointDataTypepath;isSchemaChangeEnabledMirrorsDebeziumIncludeSchemaChanges: JDBC config true/false and non-JDBC config.OpengaussCDCIT#testAddFieldWithRestore(unchanged) covers the regression end to end; the MySQL CDC restore ITs that enableschema-changes.enabledkeep exercising the [Fix][CDC][Zeta] Restore runtime schema from checkpoint after failover #11503 path../mvnw spotless:apply -pl seatunnel-connectors-v2/connector-cdc/connector-cdc-base -nsu -Dmaven.gitcommitid.skip=trueonly. Compilation, unit tests and E2E are verified by this PR's GitHub CI, per this initiative's no-local-build policy.Files
seatunnel-connectors-v2/connector-cdc/connector-cdc-base/src/main/java/org/apache/seatunnel/connectors/cdc/base/source/reader/IncrementalSourceReader.javaseatunnel-connectors-v2/connector-cdc/connector-cdc-base/src/test/java/org/apache/seatunnel/connectors/cdc/base/source/reader/IncrementalSourceReaderTest.java🤖 Generated with Claude Code